import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-07-20
 * Time: 9:09
 */
public class Test1 {
    private static int sum1 = 0;
    private static int sum2 = 0;

    private static int sum = 0;

    public static void main(String[] args) throws InterruptedException {
        long begin = System.currentTimeMillis();
        int[] array = new int[10000000];
        Random random = new Random(100);
        for (int i = 0; i < 100; i++) {
            array[i] = i;
        }
        Thread t1 = new Thread(() -> {
            for(int i = 0; i < 99; i = i + 2) {
                sum1 += array[i];
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 1; i < 100; i = i + 2) {
                sum2 += array[i];
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("sum1: " + sum1);
        System.out.println("sum2: " + sum2);
        System.out.println("sum: " + (sum1 + sum2));
        long end = System.currentTimeMillis();
        System.out.println(end - begin);


    }
}
